<?php
/**
 * Created by PhpStorm.
 * User: 17274
 * Date: 2018/4/1
 * Time: 14:36
 */

namespace app\hook\behaviors;

use think\Config;
use think\Request;
use think\Route;

class authBehavior
{
    /*
        * 单行为模式
        * 钩子权限验证
        * */
    public function run(&$params){
        $request=Request::instance();
        //只有controllerName_ 前缀才进行权限验证
        if (!(strpos($request->action(),strtolower($request->controller()))===false)){
            if($request->isPost()){
                //POST权限验证
                if (!checkAuthority(Config::get($request->controller()),$request->action())){
                    exit(json_encode(op_noper()));
                }
            }
            //GET权限验证
            if(!checkAuthority(Config::get($request->controller()),$request->action())){
                exit(forbidden(js_css()));
            }

        }
    }
}